home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / itc / cc1.spur / recog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-08-30  |  23.5 KB  |  952 lines

  1. /* Subroutines used by or related to instruction recognition.
  2.    Copyright (C) 1987, 1988 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY.  No author or distributor
  8. accepts responsibility to anyone for the consequences of using it
  9. or for whether it serves any particular purpose or works at all,
  10. unless he says so in writing.  Refer to the GNU CC General Public
  11. License for full details.
  12.  
  13. Everyone is granted permission to copy, modify and redistribute
  14. GNU CC, but only under the conditions described in the
  15. GNU CC General Public License.   A copy of this license is
  16. supposed to have been given to you along with GNU CC so you
  17. can know your rights and responsibilities.  It should be in a
  18. file named COPYING.  Among other things, the copyright notice
  19. and this notice must be preserved on all copies.  */
  20.  
  21.  
  22. #include "config.h"
  23. #include "rtl.h"
  24. #include <stdio.h>
  25. #include "insn-config.h"
  26. #include "recog.h"
  27. #include "regs.h"
  28. #include "hard-reg-set.h"
  29.  
  30. static int inequality_comparisons_p ();
  31.  
  32. /* Nonzero means allow operands to be volatile.
  33.    This is 1 if you use recog_memoized, 0 if you don't.
  34.    init_recog and recog_memoized are responsible for setting it.
  35.    This way of handling it is not really clean and will be change later.  */
  36.  
  37. int volatile_ok;
  38.  
  39. rtx recog_addr_dummy;
  40.  
  41. /* On return from `constrain_operands', indicate which alternative
  42.    was satisfied.  */
  43.  
  44. int which_alternative;
  45.  
  46. /* Initialize data used by the function `recog'.
  47.    This must be called once in the compilation of a function
  48.    before any insn recognition may be done in the function.  */
  49.  
  50. void
  51. init_recog ()
  52. {
  53.   volatile_ok = 0;
  54.   recog_addr_dummy = gen_rtx (MEM, VOIDmode, 0);
  55. }
  56.  
  57. /* Try recognizing the instruction INSN,
  58.    and return the code number that results.
  59.    Remeber the code so that repeated calls do not
  60.    need to spend the time for actual rerecognition.
  61.  
  62.    This function is the normal interface to instruction recognition.
  63.    The automatically-generated function `recog' is normally called
  64.    through this one.  (The only exception is in combine.c.)  */
  65.  
  66. int
  67. recog_memoized (insn)
  68.      rtx insn;
  69. {
  70.   volatile_ok = 1;
  71.   if (INSN_CODE (insn) < 0)
  72.     INSN_CODE (insn) = recog (PATTERN (insn), insn);
  73.   return INSN_CODE (insn);
  74. }
  75.  
  76. /* Return 1 if the insn following INSN does not contain
  77.    any ordered tests applied to the condition codes.
  78.    EQ and NE tests do not count.  */
  79.  
  80. int
  81. next_insn_tests_no_inequality (insn)
  82.      rtx insn;
  83. {
  84.   register rtx next = NEXT_INSN (insn);
  85.  
  86.   return ((GET_CODE (next) == JUMP_INSN
  87.        || GET_CODE (next) == INSN
  88.        || GET_CODE (next) == CALL_INSN)
  89.       && ! inequality_comparisons_p (PATTERN (next)));
  90. }
  91.  
  92. static int
  93. inequality_comparisons_p (x)
  94.      rtx x;
  95. {
  96.   register char *fmt;
  97.   register int len, i;
  98.   register enum rtx_code code = GET_CODE (x);
  99.  
  100.   switch (code)
  101.     {
  102.     case REG:
  103.     case PC:
  104.     case CC0:
  105.     case CONST_INT:
  106.     case CONST_DOUBLE:
  107.     case CONST:
  108.     case LABEL_REF:
  109.     case SYMBOL_REF:
  110.       return 0;
  111.  
  112.     case LT:
  113.     case LTU:
  114.     case GT:
  115.     case GTU:
  116.     case LE:
  117.     case LEU:
  118.     case GE:
  119.     case GEU:
  120.       return (XEXP (x, 0) == cc0_rtx || XEXP (x, 1) == cc0_rtx);
  121.     }
  122.  
  123.   len = GET_RTX_LENGTH (code);
  124.   fmt = GET_RTX_FORMAT (code);
  125.  
  126.   for (i = 0; i < len; i++)
  127.     {
  128.       if (fmt[i] == 'e')
  129.     {
  130.       if (inequality_comparisons_p (XEXP (x, i)))
  131.         return 1;
  132.     }
  133.       else if (fmt[i] == 'E')
  134.     {
  135.       register int j;
  136.       for (j = XVECLEN (x, i) - 1; j >= 0; j--)
  137.         if (inequality_comparisons_p (XVECEXP (x, i, j)))
  138.           return 1;
  139.     }
  140.     }
  141.         
  142.   return 0;
  143. }
  144.  
  145. /* Return 1 if OP is a valid general operand for machine mode MODE.
  146.    This is either a register reference, a memory reference,
  147.    or a constant.  In the case of a memory reference, the address
  148.    is checked for general validity for the target machine.
  149.  
  150.    Register and memory references must have mode MODE in order to be valid,
  151.    but some constants have no machine mode and are valid for any mode.
  152.  
  153.    If MODE is VOIDmode, OP is checked for validity for whatever mode
  154.    it has.
  155.  
  156.    The main use of this function is as a predicate in match_operand
  157.    expressions in the machine description.  */
  158.  
  159. int
  160. general_operand (op, mode)
  161.      register rtx op;
  162.      enum machine_mode mode;
  163. {
  164.   register enum rtx_code code = GET_CODE (op);
  165.   int mode_altering_drug = 0;
  166.  
  167.   if (mode == VOIDmode)
  168.     mode = GET_MODE (op);
  169.  
  170.   if (CONSTANT_P (op))
  171.     return ((GET_MODE (op) == VOIDmode || GET_MODE (op) == mode)
  172.         && LEGITIMATE_CONSTANT_P (op));
  173.  
  174.   /* Except for certain constants with VOIDmode, already checked for,
  175.      OP's mode must match MODE if MODE specifies a mode.  */
  176.  
  177.   if (GET_MODE (op) != mode)
  178.     return 0;
  179.  
  180.   while (code == SUBREG)
  181.     {
  182.       op = SUBREG_REG (op);
  183.       code = GET_CODE (op);
  184.       mode_altering_drug = 1;
  185.     }
  186.   if (code == REG)
  187.     return 1;
  188.   if (code == CONST_DOUBLE)
  189.     return LEGITIMATE_CONSTANT_P (op);
  190.   if (code == MEM)
  191.     {
  192.       register rtx y = XEXP (op, 0);
  193.       if (! volatile_ok && op->volatil)
  194.     return 0;
  195.       GO_IF_LEGITIMATE_ADDRESS (mode, y, win);
  196.     }
  197.   return 0;
  198.  
  199.  win:
  200.   if (mode_altering_drug)
  201.     return ! mode_dependent_address_p (XEXP (op, 0));
  202.   return 1;
  203. }
  204.  
  205. /* Return 1 if OP is a valid memory address for a memory reference
  206.    of mode MODE.
  207.  
  208.    The main use of this function is as a predicate in match_operand
  209.    expressions in the machine description.  */
  210.  
  211. int
  212. address_operand (op, mode)
  213.      register rtx op;
  214.      enum machine_mode mode;
  215. {
  216.   return memory_address_p (mode, op);
  217. }
  218.  
  219. /* Return 1 if OP is a register reference of mode MODE.
  220.    If MODE is VOIDmode, accept a register in any mode.
  221.  
  222.    The main use of this function is as a predicate in match_operand
  223.    expressions in the machine description.  */
  224.  
  225. int
  226. register_operand (op, mode)
  227.      register rtx op;
  228.      enum machine_mode mode;
  229. {
  230.   if (GET_MODE (op) != mode && mode != VOIDmode)
  231.     return 0;
  232.  
  233.   while (GET_CODE (op) == SUBREG)
  234.     op = SUBREG_REG (op);
  235.  
  236.   return GET_CODE (op) == REG;
  237. }
  238.  
  239. /* Return 1 if OP is a valid immediate operand for mode MODE.
  240.  
  241.    The main use of this function is as a predicate in match_operand
  242.    expressions in the machine description.  */
  243.  
  244. int
  245. immediate_operand (op, mode)
  246.      register rtx op;
  247.      enum machine_mode mode;
  248. {
  249.   return ((CONSTANT_P (op)
  250.        || (GET_CODE (op) == CONST_DOUBLE
  251.            && (GET_MODE (op) == mode || mode == VOIDmode)))
  252.       && LEGITIMATE_CONSTANT_P (op));
  253. }
  254.  
  255. /* Return 1 if OP is a general operand that is not an immediate operand.  */
  256.  
  257. int
  258. nonimmediate_operand (op, mode)
  259.      register rtx op;
  260.      enum machine_mode mode;
  261. {
  262.   return (general_operand (op, mode)
  263.       && ! CONSTANT_P (op) && GET_CODE (op) != CONST_DOUBLE);
  264. }
  265.  
  266. /* Return 1 if OP is a register reference or immediate value of mode MODE.  */
  267.  
  268. int
  269. nonmemory_operand (op, mode)
  270.      register rtx op;
  271.      enum machine_mode mode;
  272. {
  273.   if (CONSTANT_P (op)
  274.       || (GET_CODE (op) == CONST_DOUBLE
  275.       && (GET_MODE (op) == mode || mode == VOIDmode)))
  276.     return LEGITIMATE_CONSTANT_P (op);
  277.  
  278.   if (GET_MODE (op) != mode && mode != VOIDmode)
  279.     return 0;
  280.  
  281.   while (GET_CODE (op) == SUBREG)
  282.     op = SUBREG_REG (op);
  283.  
  284.   return GET_CODE (op) == REG;
  285. }
  286.  
  287. /* Return 1 if OP is a valid operand that stands for pushing a
  288.    value of mode MODE onto the stack.
  289.  
  290.    The main use of this function is as a predicate in match_operand
  291.    expressions in the machine description.  */
  292.  
  293. int
  294. push_operand (op, mode)
  295.      rtx op;
  296.      enum machine_mode mode;
  297. {
  298.   if (GET_CODE (op) != MEM)
  299.     return 0;
  300.  
  301.   if (GET_MODE (op) != mode)
  302.     return 0;
  303.  
  304.   op = XEXP (op, 0);
  305.  
  306. #ifdef STACK_GROWS_DOWNWARD
  307.   if (GET_CODE (op) != PRE_DEC)
  308.     return 0;
  309. #else
  310.   if (GET_CODE (op) != PRE_INC)
  311.     return 0;
  312. #endif
  313.   return REGNO (XEXP (op, 0)) == STACK_POINTER_REGNUM;
  314. }
  315.  
  316. /* Return 1 if ADDR is a valid memory address for mode MODE.  */
  317.  
  318. int
  319. memory_address_p (mode, addr)
  320.      enum machine_mode mode;
  321.      register rtx addr;
  322. {
  323.   GO_IF_LEGITIMATE_ADDRESS (mode, addr, win);
  324.   return 0;
  325.  
  326.  win:
  327.   return 1;
  328. }
  329.  
  330. /* Return 1 if OP is a valid memory reference with mode MODE,
  331.    including a valid address.
  332.  
  333.    The main use of this function is as a predicate in match_operand
  334.    expressions in the machine description.  */
  335.  
  336. int
  337. memory_operand (op, mode)
  338.      register rtx op;
  339.      enum machine_mode mode;
  340. {
  341.   enum rtx_code code = GET_CODE (op);
  342.   int mode_altering_drug = 0;
  343.  
  344.   while (code == SUBREG)
  345.     {
  346.       op = SUBREG_REG (op);
  347.       code = GET_CODE (op);
  348.       mode_altering_drug = 1;
  349.     }
  350.  
  351.   return (GET_CODE (op) == MEM && general_operand (op, mode)
  352.       && ! (mode_altering_drug
  353.         && mode_dependent_address_p (XEXP (op, 0))));
  354. }
  355.  
  356. /* Return 1 if OP is a valid indirect memory reference with mode MODE;
  357.    that is, a memory reference whose address is a general_operand.  */
  358.  
  359. int
  360. indirect_operand (op, mode)
  361.      register rtx op;
  362.      enum machine_mode mode;
  363. {
  364.   return (GET_CODE (op) == MEM && GET_MODE (op) == mode
  365.       && general_operand (XEXP (op, 0), Pmode));
  366. }
  367.  
  368. /* If BODY is an insn body that uses ASM_OPERANDS,
  369.    return the number of operands (both input and output) in the insn.
  370.    Otherwise return 0.  */
  371.  
  372. int
  373. asm_noperands (body)
  374.      rtx body;
  375. {
  376.   int noperands;
  377.  
  378.   if (GET_CODE (body) == ASM_OPERANDS)
  379.     /* No output operands: return number of input operands.  */
  380.     return XVECLEN (body, 3);
  381.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  382.     /* Single output operand: BODY is (set OUTPUT (asm_operands ...)).  */
  383.     return XVECLEN (SET_SRC (body), 3) + 1;
  384.   else if (GET_CODE (body) == PARALLEL
  385.        && GET_CODE (XVECEXP (body, 0, 0)) == SET
  386.        && GET_CODE (SET_SRC (XVECEXP (body, 0, 0))) == ASM_OPERANDS)
  387.     /* Multiple outputs: BODY is
  388.        (parallel [(set OUTPUT0 (asm_operands ...)) ...]).  */
  389.     return XVECLEN (SET_SRC (XVECEXP (body, 0, 0)), 3) + XVECLEN (body, 0);
  390.   else
  391.     return 0;
  392. }
  393.  
  394. /* Assuming BODY is an insn body that uses ASM_OPERANDS,
  395.    copy its operands (both input and output) into the vector OPERANDS,
  396.    the locations of the operands within the insn into the vector OPERAND_LOCS,
  397.    and the constraints for the operands into CONSTRAINTS.
  398.    Write the modes of the operands into MODES.
  399.    Return the assembler-template.
  400.  
  401.    If MODES, OPERAND_LOCS, CONSTRAINTS or OPERANDS is 0,
  402.    we don't store that info.  */
  403.  
  404. char *
  405. decode_asm_operands (body, operands, operand_locs, constraints, modes)
  406.      rtx body;
  407.      rtx *operands;
  408.      rtx **operand_locs;
  409.      char **constraints;
  410.      enum machine_mode *modes;
  411. {
  412.   register int i;
  413.   int noperands;
  414.   char *template;
  415.  
  416.   if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
  417.     {
  418.       rtx asmop = SET_SRC (body);
  419.       /* Single output operand: BODY is (set OUTPUT (asm_operands ....)).  */
  420.  
  421.       noperands = XVECLEN (asmop, 3) + 1;
  422.  
  423.       /* The input operands are found in the 1st element vector.  */
  424.       /* Constraints for inputs are in the 2nd element vector.  */
  425.       for (i = 1; i < noperands; i++)
  426.     {
  427.       if (operand_locs)
  428.         operand_locs[i] = &XVECEXP (asmop, 3, i - 1);
  429.       if (operands)
  430.         operands[i] = XVECEXP (asmop, 3, i - 1);
  431.       if (constraints)
  432.         constraints[i] = XSTR (XVECEXP (asmop, 4, i - 1), 0);
  433.       if (modes)
  434.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i - 1));
  435.     }
  436.  
  437.       /* The output is in the SET.
  438.      Its constraint is in the ASM_OPERANDS itself.  */
  439.       if (operands)
  440.     operands[0] = SET_DEST (body);
  441.       if (operand_locs)
  442.     operand_locs[0] = &SET_DEST (body);
  443.       if (constraints)
  444.     constraints[0] = XSTR (asmop, 1);
  445.       if (modes)
  446.     modes[0] = GET_MODE (SET_DEST (body));
  447.       template = XSTR (asmop, 0);
  448.     }
  449.   else if (GET_CODE (body) == ASM_OPERANDS)
  450.     {
  451.       rtx asmop = body;
  452.       /* No output operands: BODY is (asm_operands ....).  */
  453.  
  454.       noperands = XVECLEN (asmop, 3);
  455.  
  456.       /* The input operands are found in the 1st element vector.  */
  457.       /* Constraints for inputs are in the 2nd element vector.  */
  458.       for (i = 0; i < noperands; i++)
  459.     {
  460.       if (operand_locs)
  461.         operand_locs[i] = &XVECEXP (asmop, 3, i);
  462.       if (operands)
  463.         operands[i] = XVECEXP (asmop, 3, i);
  464.       if (constraints)
  465.         constraints[i] = XSTR (XVECEXP (asmop, 4, i), 0);
  466.       if (modes)
  467.         modes[i] = GET_MODE (XVECEXP (asmop, 4, i));
  468.     }
  469.       template = XSTR (asmop, 0);
  470.     }
  471.   else
  472.     {
  473.       rtx asmop = SET_SRC (XVECEXP (body, 0, 0));
  474.       int nout = XVECLEN (body, 0);
  475.       int nin = XVECLEN (asmop, 3);
  476.  
  477.       noperands = XVECLEN (asmop, 3) + XVECLEN (body, 0);
  478.  
  479.       /* The input operands are found in the 1st element vector.  */
  480.       /* Constraints for inputs are in the 2nd element vector.  */
  481.       for (i = 0; i < nin; i++)
  482.     {
  483.       if (operand_locs)
  484.         operand_locs[i + nout] = &XVECEXP (asmop, 3, i);
  485.       if (operands)
  486.         operands[i + nout] = XVECEXP (asmop, 3, i);
  487.       if (constraints)
  488.         constraints[i + nout] = XSTR (XVECEXP (asmop, 4, i), 0);
  489.       if (modes)
  490.         modes[i + nout] = GET_MODE (XVECEXP (asmop, 4, i));
  491.     }
  492.       /* The outputs are in the SETs.
  493.      Their constraints are in the ASM_OPERANDS itself.  */
  494.       for (i = 0; i < nout; i++)
  495.     {
  496.       if (operands)
  497.         operands[i] = SET_DEST (XVECEXP (body, 0, i));
  498.       if (operand_locs)
  499.         operand_locs[i] = &SET_DEST (XVECEXP (body, 0, i));
  500.       if (constraints)
  501.         constraints[i] = XSTR (SET_SRC (XVECEXP (body, 0, i)), 1);
  502.       if (modes)
  503.         modes[i] = GET_MODE (SET_DEST (XVECEXP (body, 0, i)));
  504.     }
  505.       template = XSTR (asmop, 0);
  506.     }
  507.  
  508.   return template;
  509. }
  510.  
  511. extern rtx plus_constant ();
  512. extern rtx copy_rtx ();
  513.  
  514. /* Given an rtx *P, if it is a sum containing an integer constant term,
  515.    return the location (type rtx *) of the pointer to that constant term.
  516.    Otherwise, return a null pointer.  */
  517.  
  518. static rtx *
  519. find_constant_term_loc (p)
  520.      rtx *p;
  521. {
  522.   register rtx *tem;
  523.   register enum rtx_code code = GET_CODE (*p);
  524.  
  525.   /* If *P IS such a constant term, P is its location.  */
  526.  
  527.   if (code == CONST_INT || code == SYMBOL_REF || code == LABEL_REF
  528.       || code == CONST)
  529.     return p;
  530.  
  531.   /* Otherwise, if not a sum, it has no constant term.  */
  532.  
  533.   if (GET_CODE (*p) != PLUS)
  534.     return 0;
  535.  
  536.   /* If one of the summands is constant, return its location.  */
  537.  
  538.   if (XEXP (*p, 0) && CONSTANT_P (XEXP (*p, 0))
  539.       && XEXP (*p, 1) && CONSTANT_P (XEXP (*p, 1)))
  540.     return p;
  541.  
  542.   /* Otherwise, check each summand for containing a constant term.  */
  543.  
  544.   if (XEXP (*p, 0) != 0)
  545.     {
  546.       tem = find_constant_term_loc (&XEXP (*p, 0));
  547.       if (tem != 0)
  548.     return tem;
  549.     }
  550.  
  551.   if (XEXP (*p, 1) != 0)
  552.     {
  553.       tem = find_constant_term_loc (&XEXP (*p, 1));
  554.       if (tem != 0)
  555.     return tem;
  556.     }
  557.  
  558.   return 0;
  559. }
  560.  
  561. /* Return 1 if OP is a memory reference
  562.    whose address contains no side effects
  563.    and remains valid after the addition
  564.    of a positive integer less than the
  565.    size of the object being referenced.
  566.  
  567.    We assume that the original address is valid and do not check it.  */
  568.  
  569. int
  570. offsetable_memref_p (op)
  571.      rtx op;
  572. {
  573.   return ((GET_CODE (op) == MEM)
  574.       && offsetable_address_p (GET_MODE (op), XEXP (op, 0)));
  575. }
  576.  
  577. /* Return 1 if Y is a memory address which contains no side effects
  578.    and would remain valid for mode MODE
  579.    after the addition of a positive integer less than the
  580.    size of that mode.
  581.  
  582.    We assume that the original address is valid and do not check it.  */
  583.  
  584. int
  585. offsetable_address_p (mode, y)
  586.      enum machine_mode mode;
  587.      register rtx y;
  588. {
  589.   register enum rtx_code ycode = GET_CODE (y);
  590.   register rtx z;
  591.   rtx y1 = y;
  592.   rtx *y2;
  593.  
  594.   if (CONSTANT_ADDRESS_P (y))
  595.     return 1;
  596.       
  597.   /* If the expression contains a constant term,
  598.      see if it remains valid when max possible offset is added.  */
  599.  
  600.   if ((ycode == PLUS) && (y2 = find_constant_term_loc (&y1)))
  601.     {
  602.       int old = INTVAL (y1 = *y2);
  603.       int good;
  604.       INTVAL (y1) += GET_MODE_SIZE (mode) - 1;
  605.       good = memory_address_p (mode, y);
  606.       /* In any case, restore old contents of memory.  */
  607.       INTVAL (y1) = old;
  608.       return good;
  609.     }
  610.  
  611.   if (ycode == PRE_DEC || ycode == PRE_INC
  612.       || ycode == POST_DEC || ycode == POST_INC)
  613.     return 0;
  614.  
  615.   /* The offset added here is chosen as the maximum offset that
  616.      any instruction could need to add when operating on something
  617.      of the specified mode.  We assume that if Y and Y+c are
  618.      valid addresses then so is Y+d for all 0<d<c.  */
  619.  
  620.   z = plus_constant (y, GET_MODE_SIZE (mode) - 1);
  621.  
  622.   return memory_address_p (mode, z);
  623. }
  624.  
  625. /* Return 1 if ADDR is an address-expression whose effect depends
  626.    on the mode of the memory reference it is used in.
  627.  
  628.    Autoincrement addressing is a typical example of mode-dependence
  629.    because the amount of the increment depends on the mode.  */
  630.  
  631. int
  632. mode_dependent_address_p (addr)
  633.      rtx addr;
  634. {
  635.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, win);
  636.   return 0;
  637.  win:
  638.   return 1;
  639. }
  640.  
  641. /* Return 1 if OP is a general operand
  642.    other than a memory ref with a mode dependent address.  */
  643.  
  644. int
  645. mode_independent_operand (mode, op)
  646.      rtx op;
  647. {
  648.   rtx addr;
  649.  
  650.   if (! general_operand (mode, op))
  651.     return 0;
  652.  
  653.   if (GET_CODE (op) != MEM)
  654.     return 1;
  655.  
  656.   addr = XEXP (op, 0);
  657.   GO_IF_MODE_DEPENDENT_ADDRESS (addr, lose);
  658.   return 1;
  659.  lose:
  660.   return 0;
  661. }
  662.  
  663. /* Given an operand OP that is a valid memory reference
  664.    which satisfies offsetable_memref_p,
  665.    return a new memory reference whose address has been adjusted by OFFSET.
  666.    OFFSET should be positive and less than the size of the object referenced.
  667. */
  668.  
  669. rtx
  670. adj_offsetable_operand (op, offset)
  671.      rtx op;
  672.      int offset;
  673. {
  674.   register enum rtx_code code = GET_CODE (op);
  675.  
  676.   if (code == MEM) 
  677.     {
  678.       register rtx y = XEXP (op, 0);
  679.  
  680.       if (CONSTANT_ADDRESS_P (y))
  681.     return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  682.  
  683.       if (GET_CODE (y) == PLUS)
  684.     {
  685.       rtx z = y;
  686.       register rtx *const_loc;
  687.  
  688.       op = copy_rtx (op);
  689.       z = XEXP (op, 0);
  690.       const_loc = find_constant_term_loc (&z);
  691.       if (const_loc)
  692.         {
  693.           *const_loc = plus_constant (*const_loc, offset);
  694.           return op;
  695.         }
  696.     }
  697.  
  698.       return gen_rtx (MEM, GET_MODE (op), plus_constant (y, offset));
  699.     }
  700.   abort ();
  701. }
  702.  
  703. #ifdef REGISTER_CONSTRAINTS
  704.  
  705. /* Check the operands of an insn (found in recog_operands)
  706.    against the insn's operand constraints (found via INSN_CODE_NUM)
  707.    and return 1 if they are valid.
  708.  
  709.    WHICH_ALTERNATIVE is set to a number which indicates which
  710.    alternative of constraints was matched: 0 for the first alternative,
  711.    1 for the next, etc.
  712.  
  713.    In addition, when two operands are match
  714.    and it happens that the output operand is (reg) while the
  715.    input operand is --(reg) or ++(reg) (a pre-inc or pre-dec),
  716.    make the output operand look like the input.
  717.    This is because the output operand is the one the template will print.
  718.  
  719.    This is used in final, just before printing the assembler code.  */
  720.  
  721. struct funny_match
  722. {
  723.   int this, other;
  724. };
  725.  
  726. int
  727. constrain_operands (insn_code_num)
  728.      int insn_code_num;
  729. {
  730.   char *constraints[MAX_RECOG_OPERANDS];
  731.   register int c;
  732.   int noperands = insn_n_operands[insn_code_num];
  733.  
  734.   struct funny_match funny_match[MAX_RECOG_OPERANDS];
  735.   int funny_match_index;
  736.  
  737.   if (noperands == 0)
  738.     return 1;
  739.  
  740.   for (c = 0; c < noperands; c++)
  741.     constraints[c] = insn_operand_constraint[insn_code_num][c];
  742.  
  743.   which_alternative = 0;
  744.  
  745.   while (*constraints[0])
  746.     {
  747.       register int opno;
  748.       int lose = 0;
  749.       funny_match_index = 0;
  750.  
  751.       for (opno = 0; opno < noperands; opno++)
  752.     {
  753.       register rtx op = recog_operand[opno];
  754.       register char *p = constraints[opno];
  755.       int win = 0;
  756.       int val;
  757.  
  758.       /* `alter_subreg' should already have converted any SUBREG
  759.          that appears at the level of an operand.  */
  760.       while (GET_CODE (op) == SUBREG)
  761.         abort ();
  762.  
  763.       while (*p && (c = *p++) != ',')
  764.         switch (c)
  765.           {
  766.           case '=':
  767.           case '+':
  768.           case '?':
  769.           case '#':
  770.           case '!':
  771.           case '*':
  772.           case '%':
  773.         break;
  774.  
  775.           case '0':
  776.           case '1':
  777.           case '2':
  778.           case '3':
  779.           case '4':
  780.         /* This operand must be the same as a previous one.  */
  781.         /* This kind of constraint is used for instructions such
  782.            as add when they take only two operands.  */
  783.         /* Note that the lower-numbered operand is passed first.  */
  784.         val = operands_match_p (recog_operand[c - '0'],
  785.                     recog_operand[opno]);
  786.         if (val != 0)
  787.           win = 1;
  788.         /* If output is *x and input is *--x,
  789.            arrange later to change the output to *--x as well,
  790.            since the output op is the one that will be printed.  */
  791.         if (val == 2)
  792.           {
  793.             funny_match[funny_match_index].this = opno;
  794.             funny_match[funny_match_index++].other = c - '0';
  795.           }
  796.         break;
  797.  
  798.           case 'p':
  799.         /* p is used for address_operands, and everything
  800.            that must be checked was checked already.  */
  801.         win = 1;
  802.         break;
  803.  
  804.         /* No need to check general_operand again;
  805.            it was done in insn-recog.c.  */
  806.           case 'g':
  807.         /* Anything goes unless it is a REG and really has a hard reg
  808.            but the hard reg is not in the class GENERAL_REGS.  */
  809.         if (GENERAL_REGS == ALL_REGS
  810.             || GET_CODE (op) != REG
  811.             || (REGNO (op) >= FIRST_PSEUDO_REGISTER
  812.             && reg_renumber[REGNO (op)] < 0)
  813.             || reg_renumbered_fits_class_p (op, GENERAL_REGS, 0,
  814.                             GET_MODE (op)))
  815.           win = 1;
  816.         break;
  817.  
  818.           case 'r':
  819.         if (GET_CODE (op) == REG
  820.             && (GENERAL_REGS == ALL_REGS
  821.             || reg_renumbered_fits_class_p (op, GENERAL_REGS,
  822.                             0, GET_MODE (op))))
  823.           win = 1;
  824.         break;
  825.  
  826.           case 'm':
  827.         if (GET_CODE (op) == MEM)
  828.           win = 1;
  829.         break;
  830.  
  831.           case '<':
  832.         if (GET_CODE (op) == MEM
  833.             && (GET_CODE (XEXP (op, 0)) == PRE_DEC
  834.             || GET_CODE (XEXP (op, 0)) == POST_DEC))
  835.           win = 1;
  836.         break;
  837.  
  838.           case '>':
  839.         if (GET_CODE (op) == MEM
  840.             && (GET_CODE (XEXP (op, 0)) == PRE_INC
  841.             || GET_CODE (XEXP (op, 0)) == POST_INC))
  842.           win = 1;
  843.         break;
  844.  
  845.           case 'F':
  846.         if (GET_CODE (op) == CONST_DOUBLE)
  847.           win = 1;
  848.         break;
  849.  
  850.           case 'G':
  851.           case 'H':
  852.         if (GET_CODE (op) == CONST_DOUBLE
  853.             && CONST_DOUBLE_OK_FOR_LETTER_P (op, c))
  854.           win = 1;
  855.         break;
  856.  
  857.           case 's':
  858.         if (GET_CODE (op) == CONST_INT)
  859.           break;
  860.           case 'i':
  861.         if (CONSTANT_P (op))
  862.           win = 1;
  863.         break;
  864.  
  865.           case 'n':
  866.         if (GET_CODE (op) == CONST_INT)
  867.           win = 1;
  868.         break;
  869.  
  870.           case 'I':
  871.           case 'J':
  872.           case 'K':
  873.           case 'L':
  874.           case 'M':
  875.         if (GET_CODE (op) == CONST_INT
  876.             && CONST_OK_FOR_LETTER_P (INTVAL (op), c))
  877.           win = 1;
  878.         break;
  879.  
  880.           case 'o':
  881.         if (offsetable_memref_p (op))
  882.           win = 1;
  883.         break;
  884.  
  885.           default:
  886.         if (GET_CODE (op) == REG
  887.             && reg_renumbered_fits_class_p (op,
  888.                             REG_CLASS_FROM_LETTER (c),
  889.                             0, GET_MODE (op)))
  890.           win = 1;
  891.           }
  892.  
  893.       constraints[opno] = p;
  894.       /* If this operand did not win somehow,
  895.          this alternative loses.  */
  896.       if (! win)
  897.         lose = 1;
  898.     }
  899.       /* This alternative won; the operands are ok.
  900.      Change whichever operands this alternative says to change.  */
  901.       if (! lose)
  902.     {
  903.       while (--funny_match_index >= 0)
  904.         {
  905.           recog_operand[funny_match[funny_match_index].other]
  906.         = recog_operand[funny_match[funny_match_index].this];
  907.         }
  908.       return 1;
  909.     }
  910.  
  911.       which_alternative++;
  912.     }
  913.   return 0;
  914. }
  915.  
  916. /* Return 1 iff OPERAND (assumed to be a REG rtx)
  917.    is a hard reg in class CLASS when its regno is offsetted by OFFSET
  918.    and changed to mode MODE,
  919.    or is a pseudo reg allocated into such a hard reg.
  920.    If REG occupies multiple hard regs, all of them must by in CLASS.  */
  921.  
  922. int
  923. reg_renumbered_fits_class_p (operand, class, offset, mode)
  924.      rtx operand;
  925.      register enum reg_class class;
  926.      int offset;
  927.      enum machine_mode mode;
  928. {
  929.   if (GET_CODE (operand) == REG)
  930.     {
  931.       register int regno = REGNO (operand);
  932.       if (reg_renumber[regno] >= 0)
  933.     regno = reg_renumber[regno];
  934.       if (regno < FIRST_PSEUDO_REGISTER
  935.       && TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  936.                 regno + offset))
  937.     {
  938.       register int sr;
  939.       regno += offset;
  940.       for (sr = HARD_REGNO_NREGS (regno, mode) - 1;
  941.            sr > 0; sr--)
  942.         if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class],
  943.                      regno + sr))
  944.           break;
  945.       return sr == 0;
  946.     }
  947.     }
  948.   return 0;
  949. }
  950.  
  951. #endif /* REGISTER_CONSTRAINTS */
  952.